﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace chessLogic
{
    public class Position
    {
        private int number;
        private char letter;

        public char Letter 
        { get { return this.letter; } }
        public int Number
        { get { return this.number; } }

        public Position(char collumn, int row)
        {
            setPosition(collumn, row);
        }
        public Position(string notation)
        {
            setPosition(notation[0], Int32.Parse(notation[1].ToString()) - 1);
        }
        public bool Equals(Position position)
        {
            return this.number == position.Number && this.Letter == position.Letter;
        }
        public void setPosition(char collumn, int row)
        {
            this.number = row;
            this.letter = collumn;
        }
        public bool IsOnBoard()
        {
            return this.Number <= 7 && this.Number >= 0 && this.GetCollNum() != -1;
        }
        public int GetCollNum()
        {
            switch (this.Letter)
            {
                case 'a':
                    return 0;
                case 'b':
                    return 1;
                case 'c':
                    return 2;
                case 'd':
                    return 3;
                case 'e':
                    return 4;
                case 'f':
                    return 5;
                case 'g':
                    return 6;
                case 'h':
                    return 7;
                default:
                    return -1;
            }
        }
        public bool ContainChar(char ch)
        {
            if (Char.IsDigit(ch))
                return (Int32.Parse(ch.ToString()) - 1) == number;
            else
                return ch == letter;
        }
        public override string ToString()
        { 
            int notationNum = this.number + 1;
            return "" + this.letter + notationNum;
        }
    }
}
